package roborally.script.singleCondition;

import roborally.model.Energy;
import roborally.model.Robot;
import roborally.script.SingleCondition;
import be.kuleuven.cs.som.annotate.*;
import be.kuleuven.cs.som.taglet.*;

/**
 * @author Joren VERSPEURT
 * @author Mathieu REYMOND
 * @version 3.0
 * 
 * The class representing a EnergyAtLeast statement in the RoboRally script language.
 */
public class EnergyAtLeast extends SingleCondition {

	/**
	 * Create a new EnergyAtLeast Condition with a given Robot, and a given amount of energy.
	 * @param robot The Robot this Condition will apply to.
	 * @param energy The energy that will be compared to the <code>robot</code>'s energy.
	 */
	public EnergyAtLeast(Robot robot, double energy) {
		super(robot);
		this.energy = energy;
	}
	
	/**
	 * An alternate EnergyAtLeast constructor, where the energy is given as a String type.
	 * This String will be converted to a number.
	 * @param robot The Robot this Condition will apply to.
	 * @param energy The String representing the energy that will be compared to the <code>robot</code>'s energy.
	 */
	public EnergyAtLeast(Robot robot, String energy){
		super(robot);
		this.energy = Double.valueOf(energy);
	}
	
	/**
	 * Get this Condition's energy value.
	 */
	@Basic @Immutable
	public final double getEnergy(){
		return energy;
	}
	
	/**
	 * The energy that will be compared to the <code>robot</code>'s energy.
	 */
	private final double energy;

	/**
	 * This Condition is true if <code>robot</code>'s energy value is greater or equal to <code>energy</code>.
	 */
	@Override
	public boolean isTrue() {
		
		return robot.getEnergy().getValueIn(Energy.Unit.WS) >= energy;
	}
	
	/**
	 * The script word for this command followed by it's <code>energy</code> parameter.
	 */
	@Override
	public String toString() {
		return "energy-at-least " + energy;
	}
}
